package com.example.sofclick;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;

public class MainActivity extends Activity {

	@Override
	// protected void onCreate(Bundle savedInstanceState) {
	// super.onCreate(savedInstanceState);
	// setContentView(R.layout.activity_main);
	// }
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.notes);
		
		TableLayout aTable = (TableLayout) findViewById(R.id.amortization);
		String[][] amortValues = this.getTestMatrix(40, 20);
		appendRows(aTable, amortValues);
		TableLayout leftColumn = (TableLayout) findViewById(R.id.left_static);
		appendLeftrows(leftColumn, amortValues);
		TableLayout firstRow = (TableLayout) findViewById(R.id.col_names);
		apentdUpColums(firstRow, amortValues);
	}

	private void appendRows(TableLayout table, String[][] amortization) {
		int rowSize = amortization.length;
		int colSize = (amortization.length > 0) ? amortization[0].length : 0;
		for (int i = 0; i < rowSize; i++) {
			TableRow row = new TableRow(this);

			for (int j = 0; j < colSize; j++) {
				TextView c = new TextView(this);
				System.out.println(amortization[i][j]);
				c.setText(amortization[i][j]);
				c.setPadding(3, 3, 3, 3);
				row.addView(c);
			}
			table.addView(row, new TableLayout.LayoutParams());
		}
	}

	private void appendLeftrows(TableLayout table, String[][] amortization) {
		int rowSize = amortization.length;
		for (int i = 0; i < rowSize; i++) {
			TableRow row = new TableRow(this);
			TextView c = new TextView(this);
			c.setText(amortization[i][0]);
			c.setPadding(3, 3, 3, 3);
			row.addView(c);

			table.addView(row, new TableLayout.LayoutParams());
		}
	}

	private void apentdUpColums(TableLayout table, String[][] amortization) {
		int colSize = amortization[0].length;
		TableRow row = new TableRow(this);
		for (int j = 0; j < colSize; j++) {
			TextView c = new TextView(this);
			c.setText(amortization[10][j]);
			c.setPadding(3, 3, 3, 3);
			row.addView(c);
		}
		table.addView(row, new TableLayout.LayoutParams());
	}

	public String[][] getTestMatrix(int filas, int columnas) {
		String[][] data = new String[filas][columnas];
		for (int co = 0; co < columnas; co++) {
			for (int fi = 0; fi < filas; fi++) {
				data[fi][co] = "val col=" + co + " fi=" + fi;
			}
		}
		return data;

	}

	

}
